﻿@using eLoan.Models;
@model AgentItineraryModel

@{
    ViewBag.Title = "Agent Itinerary";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Agent Itinerary</h2>
        <ol class="breadcrumb">
            <li>
                Reports
            </li>
            <li class="active">
                <strong>Agent Itinerary</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
            @using (Html.BeginForm("RefreshItineraryPDF", "Report", FormMethod.Post, new { id = "saveForm" }))
            {
                <fieldset>
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)
                    <div class="ibox-title">
                        <div class="divSearch">
                            <table class="table-search">
                                <tr>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Branches)</span>
                                        @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "text-box single-line", @onchange = "GetAgents()" })
                                    </td>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Agents)</span>
                                        @Html.DropDownListFor(m => m.SelectedAgentID, Model.Agents, new { @id = "ddlAgents", @class = "text-box single-line" })
                                    </td>
                                    <td class="tdFixed">
                                        @Html.TextBoxFor(m => m.SearchText, new { @class = "single-line" })
                                    </td>
                                    <td class="tdFixed">
                                        <button type="submit" id="btnRefresh" class="btn btn-primary" value=" refresh" style="margin-bottom: 0px">Search</button>
                                    </td>
                                    <td class="tdAlignRight">
                                        <button type="submit" id="btnExport" class="btn btn-primary btnSearch" name="command" value="Export">Export to pdf</button>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                <div class="ibox-title">
                    <div class="pull-left">
                        <h3>No. of Borrowers: @Model.AgentItineraries.Count().ToString("#,###,##0")</h3>
                    </div>
                    <div class="pull-right">
                        <h3>
                            Short Over (+) : @Model.ShortOverPlus.ToString("#,###,##0.00")
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            Short Over (-) : @Model.ShortOverMinus.ToString("#,###,##0.00")
                        </h3>
                    </div>
                </div>
                <div class="ibox-content">
                    <table class="table table-bordered table-List">
                        <thead>
                            <tr>
                                <th>Borrower</th>
                                <th>Contact Numbers</th>
                                <th>Maturity Date</th>
                                <th>Outstanding Balance</th>
                                <th>Penalty Balance</th>
                                <th>Weekly Payment</th>
                                <th>Short / Over</th>
                                <th>Amount Paid</th>
                                <th>Signature</th>
                            </tr>
                        </thead>
                        <tbody>
                            @for (var i = 0; i < Model.AgentItineraries.Count(); i++)
                            {
                                <tr>
                                    <td>
                                        @Html.ValueFor(m => m.AgentItineraries[i].BorrowerName)
                                        @Html.HiddenFor(m => m.AgentItineraries[i].BorrowerName)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.AgentItineraries[i].ContactNumbers)
                                        @Html.HiddenFor(m => m.AgentItineraries[i].ContactNumbers)
                                    </td>
                                    <td>
                                        @Html.ValueFor(m => m.AgentItineraries[i].PaymentEndDate, "{0:MMM/dd/yyyy}")
                                        @Html.HiddenFor(m => m.AgentItineraries[i].PaymentEndDate)
                                    </td>
                                    <td style="text-align:right">
                                        @Html.ValueFor(m => m.AgentItineraries[i].OutstandingBalance, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.AgentItineraries[i].OutstandingBalance)
                                    </td>
                                    <td style="text-align:right">
                                        @Html.ValueFor(m => m.AgentItineraries[i].PenaltyBalance, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.AgentItineraries[i].PenaltyBalance)
                                    </td>
                                    <td style="text-align:right">
                                        @Html.ValueFor(m => m.AgentItineraries[i].WeeklyPayment, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.AgentItineraries[i].WeeklyPayment)
                                    </td>
                                    <td style="text-align:right">
                                        @Html.ValueFor(m => m.AgentItineraries[i].ShortOver, "{0:#,###,##0.00}")
                                        @Html.HiddenFor(m => m.AgentItineraries[i].ShortOver)
                                    </td>
                                    <td></td>
                                    <td></td>
                                </tr>
                            }
                        </tbody>
                    </table>
                    
                </div>
                </fieldset>
            }
            </div>
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")

    <style>

    .divScroll {
        height: 400px;
        overflow-x: scroll;
        border: solid 1px #EBEBEB;
    }

    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
    }

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search td {
            margin: 10px 10px 10px 10px;
            padding: 10px 10px 10px 10px;
            vertical-align: bottom;
        }
        
        .table-search .tdAlignRight {
            text-align: right;
        }

        .table-search .tdFixed {
            width:20%;
        }

            .table-search td .btnSearch {
                margin-bottom: 0px;
            }

            
            .table-search td span {
                margin-left: 7px;
            }
</style>

}

@section Scripts {
@Scripts.Render("~/plugins/dataTables")

    <script id="methods" type="text/javascript">

        $(document).ready(function () {

            $('.table-List').dataTable({
                ordering: true,
                searching: false,
                paging: false,
                scrollY: 400
            });

            $(window).keydown(function (event) {
                if (event.keyCode == 13) {
                    Refresh();
                    return false;
                }
            });

        });

        function GetAgents()
        {
            var val = $('#ddlBranches').val();
            var subItems = "";
        
            $.getJSON("@Url.Action("GetAgents","Loan")", { branchCode: val },
                function (data) {

                    $.each(data, function (index, item) {

                        subItems += "<option value='" + $.trim(item.Value) + "'>" + $.trim(item.Text) + "</option>"

                });
                
                $("#ddlAgents").html(subItems)
            });
 
        }

        function Refresh() {
            document.getElementById('btnRefresh').click();
        }

    </script>
}